//
//  PPLVC.m
//  SYPerfectDemo
//
//  Created by Lssyyy on 2019/7/10.
//  Copyright © 2019年 Lssyyy. All rights reserved.
//

#import "PPLVC.h"
#import "MyLayout.h"
#import "PPModel.h"
#import "MyCollectionViewCell.h"
@interface PPLVC()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong) UICollectionView *collectionView;
@end

@implementation PPLVC{
    NSMutableArray *_dataArray;
    NSMutableData *_data;
}
- (void)viewDidLoad{
    [super viewDidLoad];
    self.title = @"瀑布流";
    
    _data=[[NSMutableData alloc] init];
    
    _dataArray=[[NSMutableArray alloc] init];
    for (int i=0; i<20; i++) {
        PPModel *model=[[PPModel alloc] init];
        model.imgHight=arc4random()%300+50;
        [_dataArray addObject:model];
    }
    
    MyLayout *myLayout=[[MyLayout alloc]init];
    myLayout.dataArray=_dataArray;
    _collectionView=[[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:myLayout];
    _collectionView.delegate=self;
    _collectionView.dataSource=self;
    _collectionView.backgroundColor=[UIColor whiteColor];
    [_collectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"CellID"];
    
    [self.view addSubview:_collectionView];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _dataArray.count;
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    MyCollectionViewCell *cel=[collectionView dequeueReusableCellWithReuseIdentifier:@"CellID" forIndexPath:indexPath];
    [cel filldata:_dataArray[indexPath.row]];
    return cel;
    
}
@end
